#include "Enemy.h"

Enemy::Enemy(void){
	Ex = 16;
	Ey = 16;
	tEx = 16;
	tEy = 16;
	dir = 4;
	direction = 4;
};

Enemy::~Enemy(void){


};
void Enemy::go(){

	if ((!up)&&(!down)&&(!left)&&(!right)){
	Map M;
	M.Nuskaitymas();

	
	int min = 1, max = 4;
	int range = (max - min) + 1;

	
//------------------------------- ENEMY INTELEKTAS :DD ---------------------------------------------------

	direction = min + int(range*rand()/(RAND_MAX + 1.0)); 
	
	while ((dir == 1)&&(direction == 2)) direction = min + int(range*rand()/(RAND_MAX + 1.0)); 
	while ((dir == 2)&&(direction == 1)) direction = min + int(range*rand()/(RAND_MAX + 1.0)); 
	while ((dir == 3)&&(direction == 4)) direction = min + int(range*rand()/(RAND_MAX + 1.0)); 
	while ((dir == 4)&&(direction == 3)) direction = min + int(range*rand()/(RAND_MAX + 1.0)); 




  if (direction == 1)
	  if (M.Tikrinti((Ex/2) + 1, Ey/2)){ Ex = Ex + 2; right = true;}
 if (direction == 2)
	 if (M.Tikrinti((Ex/2) - 1, Ey/2)){ Ex = Ex - 2; left = true;}
 if (direction == 3)
	 if (M.Tikrinti(Ex/2, (Ey/2) + 1)) {Ey = Ey + 2; up = true; }
 if (direction == 4)
	 if (M.Tikrinti(Ex/2, (Ey/2) - 1)) {Ey = Ey - 2; down = true; }

	dir = direction;

	}
}